//
//  list.h
//  cobalt
//
//  Created by Nicolas Godbout on 2013-08-19.
//  Copyright (c) 2013 Nicolas Godbout. All rights reserved.
//

#ifndef __cobalt__list__
#define __cobalt__list__

#include <memory>

template <class T>
class ListCell {
    T           head;
    std::unique_ptr<ListCell<T>>    rest;
};

template <class T>
class List {
    std::unique_ptr<ListCell<T>>    list;
public:
    <#member functions#>
};

#define LIST(TYPE) struct List_##TYPE

#define DECLARE_LIST(TYPE) \
struct List_##TYPE { \
TYPE                head; \
struct List_##TYPE  *rest; \
}

list_ptr
list_empty();

list_ptr
list_singleton(void* head);

list_ptr
list_cons (void* head, list_ptr rest);

list_cell
list_uncons (list_ptr list);

// Given two sorted list, yield their (stable) sorted union
list_ptr
list_merge (list_ptr list1, list_ptr list2);

// void
// list_merge_tail (list_ptr* res, list_ptr list1, list_ptr list2);


#endif /* defined(__cobalt__list__) */
